package com.snowy.hidden.config;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.snowy.hidden.user.domain.model.DevConfig;
import com.snowy.hidden.user.mapper.DevConfigMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

/**
 * @ClassName: ConfigUtil
 * @author: hjl
 * @version V1.0 读取yml中配置信息
 */
@Component
@Slf4j
public class ConfigDev {

	private static HashMap<String,Integer> offsetMap;

	@Autowired
	private DevConfigMapper devConfigMapper;


	/**
	 *  初始化偏移量
	 */
	public   void initOffSetHamp(){
		if (ObjectUtil.isEmpty(offsetMap)){
			offsetMap=new HashMap<>();
			//读取偏移配置
			LambdaQueryWrapper<DevConfig> queryWrapper=new LambdaQueryWrapper<>();
			queryWrapper.in(DevConfig::getConfigKey,"1543842934270394370","1543842934270394371","1543842934270394372","1543842934270394373");
			         List<DevConfig> devConfigSet=devConfigMapper.selectList(queryWrapper);
					 devConfigSet.stream().forEach(devConfig->{
						 System.out.println(devConfig.getConfigKey()+"==="+Integer.valueOf(devConfig.getConfigValue()));
						 offsetMap.put(devConfig.getConfigKey(),Integer.valueOf(devConfig.getConfigValue()));
					 });

		}
	}


	/**
	 * 获取偏移量 默认20
	 * @param lineArea
	 * @return
	 */
	public  Integer getOffSetByLineArea(String lineArea){
		Integer  of= offsetMap.getOrDefault(lineArea,20);
		return offsetMap.getOrDefault(lineArea,20);
	}




}
